const app = getApp()
function jumpurl(linkinfo){
  wx.setStorageSync('linkinfo',linkinfo);
  var openType=linkinfo.type
  var type_name=linkinfo.title
  var tabbar_index=0;
  var list=wx.getStorageSync('tabbar').list
  for(var s=0;s<list.length; s++){
      if(list[s].link.type==openType){
        tabbar_index=s
      }
  }
  if(openType=='miniapp'){
    wx.navigateToMiniProgram({
      appId:linkinfo.appid,
      path:linkinfo.url+'?id='+linkinfo.id,
      extraData: {
        foo:'bar'
      },
      envVersion:'develop',
      success(res) {
      }
    })
  }
  if(openType=='contact'){
    return false
  }
  if(openType=='share'){
     return false
  }
  if(openType=='map'){
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success: function (res) {  //因为这里得到的是你当前位置的经纬度
        var latitude =Number(linkinfo.url.lat) 
        var longitude = Number(linkinfo.url.lng)
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          name:linkinfo.url.address,
          address:linkinfo.title,
          scale: 17
        })
      }
    })
    return false
  }
  if(openType!=='none'){
    switch (openType) {
      case 'web':
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type='+openType+'&pagetitle='+type_name+'&linkurl='+linkinfo.url,
        })
        break;
      case 'phone':
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=chat'
        })
        break;
      case 'image_class':
           wx.navigateTo({ 
              url: '/yb_shopv2/native/all/index?type='+openType+'&pagetitle='+type_name+'&img_id='+linkinfo.id,
           })
          break;
    case 'article':
            wx.navigateTo({ 
               url: '/yb_shopv2/native/all/index?type=article&id='+linkinfo.id,
            })
            break;
      case 'member':
        wx.navigateTo({
          url: '/yb_shopv2/entry/video-market/index?tabbar_type='+openType+'&tabbar_title='+type_name+'&tabbar_index='+tabbar_index
        })
        break;
      case 'services':
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=good_detail&activity=service&goods_id='+linkinfo.id,
        })
        break;
      case 'activity_group_list':
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=group_list',
        })
        break;
      case 'activity_seckill_list':
          wx.navigateTo({
            url: '/yb_shopv2/native/all/index?type=seckill_list',
          })
          break;
      case 'activity_bargain_list':
            wx.navigateTo({
              url: '/yb_shopv2/native/all/index?type=bargain_list',
            })
            break;
      case 'page_coupon_list':
        wx.navigateTo({ 
            url: '/yb_shopv2/native/all/index?type='+openType+'&pagetitle='+type_name+'&styleType=style2'
         })
         break;
      case 'goods':
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=good_detail&goods_id='+linkinfo.id+'&tabbar_title='+type_name
        })
        break;
    case 'page':
          wx.navigateTo({ 
            url: '/yb_shopv2/native/all/index?type='+openType+'&pageid='+linkinfo.id+'&pagetitle='+type_name,
         })
          break;
    case 'video_list':
            wx.navigateTo({ 
              url: '/yb_shopv2/native/all/index?type='+openType+'&pageid='+linkinfo.id+'&pagetitle='+type_name,
           })
          break;
   case 'mine_order':
            wx.navigateTo({ 
              url: '/yb_shopv2/native/all/index?type='+openType+'&page_type='+linkinfo.order_type+'&pagetitle='+type_name,
           })
          break;
    case 'address':
         if(linkinfo.parent=='confirm_order_address'){
          wx.navigateTo({ 
            url: '/yb_shopv2/native/all/index?type='+openType+'&pagetitle='+type_name+'&page_type=confirmorder',
         })
         }
          else{
            wx.navigateTo({ 
              url: '/yb_shopv2/native/all/index?type='+openType+'&pagetitle='+type_name,
           })
          }
          break;
      default:
          wx.navigateTo({ 
            url: '/yb_shopv2/native/all/index?type='+openType+'&pagetitle='+type_name,
         })
        break;
    }
  }
}
function callphone(phonenumer){
  wx.makePhoneCall({
    phoneNumber:phonenumer,
    success:function(){
      console.log('拨打成功')
    },
    fail:function(){
      console.log('拨打失败')
    }
  })
}
function animated(id) {
  var style=app.globalData.styles[id]
  var n = parseFloat(wx.getStorageSync('SystemInfo').windowWidth/375)
  var t = {}, r = {};
  var css='';
  for (let u in style) {
    if(u=="animation"){
      var b = style.animation;
      css=css+" animated " + b.animo_class+';';
    }
  }
  return css;
}
function css(id) {
  var style=app.globalData.styles[id]
  var n = parseFloat(wx.getStorageSync('SystemInfo').windowWidth/375)
  var t = {}, r = {};
  var css='';
  for (let u in style) {
    if(u=='height'||"line-height" === u || "width" === u || "font-size" === u || "top" === u || "left" === u || "right" === u || "bottom" === u){
       var h = style[u].value;
       h = (parseFloat(h)*n).toFixed(2);
       css=css+u+':'+h+'px;';
    }else if(u=="bg"){
      var c = style.bg;
      if(c.type=="color"){
        css=css+'background-color:'+c.color.color+';background:'+c.color.color+';';
      }else if(c.type=="image"){
         css=css+'background-image:'+"url(" + c.image.path + ");background-position:"+c.image.px + "% " + c.image.py + "%;"+'background-repeat:'+ c.image.repeat.repeat+';background-size:'+c.image.repeat.size+';';
      }
      else if(c.type=="gradient"){
        css=css+'background-color:rgba(255, 255, 255, 0);background:'+"-webkit-gradient(linear, left top, left bottom, from(" + c.gradient.begin + "), to(" + c.gradient.end + "));";
      }
      else if(c.type=="none"){
        css=css+'background-color:rgba(255, 255, 255, 0);background:rgba(255, 255, 255, 0);background-image:url();';
      }
    }else if(u=="image"){
          var l = style.image;
          css=css+'background-image:'+"url(" + l.path + ");";
          css=css+'background-position:'+ l.px + "% " + l.py + "%;";
          css=css+'background-repeat:'+ l.repeat.repeat+';';
          css=css+'background-size:'+l.repeat.size+';';
    }
    else if(u=="bd"){
      var f = style.bd;
      css=css+'border-top:'+f.t.width + "px " + f.t.style + " " + f.t.color+';';
      css=css+'border-right:'+f.r.width + "px " + f.r.style + " " + f.r.color+';';
      css=css+'border-bottom:'+f.b.width + "px " + f.b.style + " " + f.b.color+';';
      css=css+'border-left:'+f.l.width + "px " + f.l.style + " " + f.l.color+';';
    }
    else if(u=="br"){
      var p = style.br;
      css=css+'border-radius:'+p.tl + "px " + p.tr + "px " + p.br + "px " + p.bl + "px;";
    }else if(u=="sd"){
      var d = style.sd;
      var h = 2 * Math.PI / 360 * d.sd_angle;
      var  g = (Math.sin(h) * d.sd_width * -1).toFixed(2);
      var v = (Math.cos(h) * d.sd_width).toFixed(2);
      css=css+'box-shadow:'+g + "px " + v + "px " + d.sd_blur + "px " + d.color+';';
    }else if(u=="font"){
      var _ = style.font;
      var m = parseFloat(_.size);
      var m = Math.floor(m * n);
      var fontweight= _.isB ? 600 : 400;
      var fontstyle= _.isI ? "italic" : "normal";
      var textdecoration= _.isU ? "underline" : "unset";
      css=css+'font-family:'+_.family+";";
      css=css+'font-size:'+m + "px;";
      css=css+'color:'+_.color+";";
      css=css+'font-weight:'+fontweight+';';
      css=css+'font-style:'+fontstyle+";";
      css=css+'text-decoration:'+textdecoration+";";
      css=css+'text-align:'+_.align+";";
    }else if(u=="animation"){
      var b = style.animation;
      css=css+'animation-delay:'+b.delay + "s"+";";
      css=css+'animation-duration:'+b.duration + "s"+";";
      css=css+'animation-iteration-count:'+b["iteration-count"]+";";
      css=css+" animated " + b.animo_class+';';
    }else {
      var w = style[u].value;
      css=css+u+':'+w+';';
     }
  }
  return css;
}
module.exports = {
  animated:animated,
  css:css,
  jumpurl:jumpurl
}
